<?php
/*
 ReadThis Template Name: ReadThis
 ReadThis Template URI: http://www.xorax.info/blog/readthis/
 Description: Add an audio speaker on your post thanks to ReadSpeaker. <a href="./edit.php?page=readthis.php">Go to admin Page</a>.
 Version: 0.9.0
 Author: XoraX
 Author URI: http://www.xorax.info
*/

class readthis_template_abstract {
  var $swf; //the swf file will defined in the constructor()
  var $width;
  var $height;
  
  function readthis_template_abstract ($mode = false){
    $this->swf = trailingslashit(get_option('siteurl')).trailingslashit(PLUGINDIR).'readthis/template/'.str_replace('readthis_template_','',get_class($this)).'.swf';
    $this->width = 200;
    $this->height = 20;
  }
  
  function object($params = array()){
    $audio = get_the_audio_url();
    if(!$audio) return false;
    if(!is_array($params)) $params = array();
    
    $def_params = array( //default params of the swf override by the function parameters
      'son' => $audio,
      'bgcolor' => '#666666'
    );
    $params = array_merge($def_params, $params);
    return array(
      'swf' => $this->swf,
      'params' => $params,
    );
  }
  
  function html_object($params = array()){
    if(false == $params = $this->object($params)) return '';
    
    $params = $params['params'];
    $params_url = '';
    foreach($params as $p => $v){
      $params_url .= rawurlencode($p).'='.rawurlencode($v).'&';
    }      

    return '<div style="z-index:-100;">'.
      '<object width="'.$this->width.'" height="'.$this->height.'" data="'.$this->swf.'" type="application/x-shockwave-flash">'.
        '<param name="movie" value="'.$this->swf.'"/>'.
        '<param name="FlashVars" value="'.$params_url.'"/>' .
        '<param name="wmode" value="transparent" />'.
        '<embed width="'.$this->width.'" height="'.$this->height.'"'.
          'pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ' .
          'allowscriptaccess="sameDomain" quality="high" wmode="transparent" ' .
          'src="'.$this->swf.'" FlashVars="'.$params_url.'" />'.
      '</object>'.
      '</div>';
  }
  
  function inline($content){
    return $this->html_object().$content;
  }
  
  function widget($args) {
    extract($args);
    ?>
          <?php echo $before_widget; ?>
              <?php echo $before_title
                  . 'My ReadThis Widget'
                  . $after_title; ?>
              Hello, World!
          <?php echo $after_widget; ?>
    <?php
  }
}

?>
